
#pragma once

#include <string>
#include "db/DBRow.h"

struct sqlite3;
struct sqlite3_stmt;


class Sqlite3Stmt
{
    Sqlite3Stmt(const Sqlite3Stmt&);
    void operator=(const Sqlite3Stmt&);
public:
    Sqlite3Stmt(sqlite3* h) : handle_(h), stmt_(nullptr), col_count_(0){}

    ~Sqlite3Stmt();

    bool perpare(const std::string& sql);

    bool reset();

    bool clear_bind();

    int64_t exec();

    bool query(DBRows& rows);


    //////////////////////////////////////////////////////////////////////////
    bool bind(int index, std::nullptr_t);
    bool bind(int index, bool val);
    bool bind(int index, int8_t val);
    bool bind(int index, int16_t val);
    bool bind(int index, int32_t val);
    bool bind(int index, int64_t val);
    bool bind(int index, uint8_t val);
    bool bind(int index, uint16_t val);
    bool bind(int index, uint32_t val);
    bool bind(int index, uint64_t val);

    bool bind(int index, float val);
    bool bind(int index, double val);

    bool bind(int index, const std::string& val);
    bool bind(int index, const char* val);
    bool bind(int index, const unsigned char* val);

    bool bind(int index, const void* val, size_t len);
private:
    sqlite3*        handle_;
    sqlite3_stmt*   stmt_;
    size_t          col_count_;
};